package com.yj.generator.utils;


import java.util.Arrays;
import java.util.List;

/**
 * @author DengLin
 * @title 常用工具
 * @date 2024/07/04
 */
public class CommonUtil {
    private static final String UNDERLINE = "_";

    public static String toCamel(String oldString, boolean bigCamel) {
        StringBuilder sb = new StringBuilder();
        String[] splits = oldString.split(UNDERLINE);
        sb.append(bigCamel ? firstCharUpper(splits[0]) : splits[0]);
        for (int i = 1; i < splits.length; i++) {
            sb.append(firstCharUpper(splits[i]));
        }
        return sb.toString();
    }

    public static String firstCharUpper(String target) {
        return target.substring(0, 1).toUpperCase() + target.substring(1);
    }

    public static String firstCharLower(String target){
        return target.substring(0, 1).toLowerCase() + target.substring(1);
    }

    /**
     * 移除前缀
     * @param target
     * @param prefixList
     * @return
     */
    public static String removePrefix(String target, List<String> prefixList){
        StringBuilder sb = new StringBuilder();
        for (String prefix : prefixList) {
            if (target.startsWith(prefix)) {
                sb.append(target.substring(target.indexOf(UNDERLINE)+1));
                return sb.toString();
            }
        }
        return sb.append(target).toString();
    }

}
